package com.citycloud.ccuap.tc.oauth2.config.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.citycloud.ccuap.tc.common.result.ResultCodeEnum;
import com.citycloud.ccuap.tc.common.result.ResultObject;
import com.fasterxml.jackson.databind.ObjectMapper;

@Component
public class CustomerAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        httpServletResponse.setContentType("application/json; charset=utf-8");

        ObjectMapper mapper = new ObjectMapper();
        httpServletResponse.getWriter().print(mapper.writeValueAsString(ResultObject.getInstance().error(ResultCodeEnum.TOKEN_UNAUTHORIZED, "我愚蠢的弟弟啊 ! 你跑错厕所了 ! ")));
    }
}
